﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Document_Management
{
    public partial class FrmCuttingtool_Manager : Form
    {
        string s = "";
        string s1 = "";
        int iflag = 0;
        string flag;
        //object img;
        string tb1,tb2,tb3,tb4,tb5,tb6,tb7;
        int width, height;
        bool b刀具Search, b刀具Insert, b刀具Edit, b刀具Del;
        static string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["庫存管理"].ConnectionString;
        public FrmCuttingtool_Manager(bool b刀具Search,bool b刀具Insert,bool b刀具Edit,bool b刀具Del)
        {
            InitializeComponent();
            width = this.Size.Width;
            height = this.Size.Height;
            this.b刀具Search = b刀具Search;
            this.b刀具Insert = b刀具Insert;
            this.b刀具Edit = b刀具Edit;
            this.b刀具Del = b刀具Del;
        }
        //Form load nhan vien bao quan, 刀具保管人
        public void Load_刀具保管人()
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter("sp_刀具保管人_load", con);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                dataGrid_刀具保管人.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                dataGrid_刀具保管人.DataSource = dt;
                PublicClass.setRowNumber(dataGrid_刀具保管人);
                con.Close();
                txt_保管人代號.Text = "";
                txt_保管人姓名.Text = "";
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
        }
        //form nhap nhan vien bao quan, 刀具保管人
        private void bt新增_Click(object sender, EventArgs e)
        {
            if (!b刀具Insert)
            {
                MessageBox.Show("很抱歉，您没有权限", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }  
            try
            {
                if(txt_保管人代號.Text.ToString()==null||txt_保管人姓名.Text.ToString().Equals(""))
                    MessageBox.Show("人員代號還沒輸入資料");
                else
                {
                    SqlConnection con = new SqlConnection(connectionString);
                    con.Open();
                    String sql = "SELECT count(*) FROM 刀具保管人 WHERE 保管人代號='" + txt_保管人代號.Text.ToString() + "'";
                    SqlCommand cmd0;
                    cmd0 = new SqlCommand(sql, con);
                    if ((int)cmd0.ExecuteScalar() > 0)
                    {
                        MessageBox.Show("Error! '"+txt_保管人代號.Text.ToString()+"' 由來");
                    }
                    else
                    {
                        cmd0 = new SqlCommand("sp_刀具保管人_新增", con);
                        cmd0.CommandType = CommandType.StoredProcedure;
                        cmd0.Parameters.AddWithValue("@保管人代號", txt_保管人代號.Text.ToString());
                        cmd0.Parameters.AddWithValue("@保管人姓名", txt_保管人姓名.Text.ToString());
                        cmd0.ExecuteNonQuery();
                        MessageBox.Show("新增成功");
                        Load_刀具保管人();
                    }
                    con.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
        }

        private void btn刪除_Click(object sender, EventArgs e)
        {
            if (!b刀具Del)
            {
                MessageBox.Show("很抱歉，您没有权限", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            } 
            try
            {
                if (txt_保管人代號.Text.ToString() == null || txt_保管人姓名.Text.ToString().Equals(""))
                    MessageBox.Show("人員代號還沒輸入資料");
                else
                {
                    SqlConnection con = new SqlConnection(connectionString);
                    con.Open();
                    SqlCommand cmd0 = new SqlCommand("sp_刀具保管人_刪除", con);
                    cmd0.CommandType = CommandType.StoredProcedure;
                    cmd0.Parameters.AddWithValue("@保管人代號", txt_保管人代號.Text.ToString());
                    cmd0.ExecuteNonQuery();
                    MessageBox.Show("刪除成功");
                    Load_刀具保管人();
                    con.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
        }

        private void FrmCuttingtool_Manager_Load(object sender, EventArgs e)
        {
            
            Load_刀具保管人();
            Load_刀具();
        }

        private void dataGrid_刀具保管人_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                DataGridViewRow row = new DataGridViewRow();
                row = dataGrid_刀具保管人.Rows[e.RowIndex];
                txt_保管人代號.Text = row.Cells[0].Value.ToString();
                s = row.Cells[0].Value.ToString();
                txt_保管人姓名.Text = row.Cells[1].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
        }

        private void bt修改_Click(object sender, EventArgs e)
        {
            if (!b刀具Edit)
            {
                MessageBox.Show("很抱歉，您没有权限", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            try
            {
                if (txt_保管人代號.Text.ToString() == null || txt_保管人姓名.Text.ToString().Equals(""))
                    MessageBox.Show("人員代號還沒輸入資料");
                else
                {
                    SqlConnection con = new SqlConnection(connectionString);
                    con.Open();
                    SqlCommand cmd0 = new SqlCommand("sp_刀具保管人_修改", con);
                    cmd0.CommandType = CommandType.StoredProcedure;
                    cmd0.Parameters.AddWithValue("@保管人代號_1", s);
                    cmd0.Parameters.AddWithValue("@保管人代號_2", txt_保管人代號.Text.ToString());
                    cmd0.Parameters.AddWithValue("@保管人姓名", txt_保管人姓名.Text.ToString());
                    cmd0.ExecuteNonQuery();
                    MessageBox.Show("修改成功");
                    Load_刀具保管人();
                    con.Close();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
        }

        private void btn_取消_Click(object sender, EventArgs e)
        {
            txt_保管人代號.Text = "";
            txt_保管人姓名.Text = "";
            
        }

         //load _ 刀具
        public void Load_刀具()
        {
            SqlConnection con = new SqlConnection(connectionString);
            try
            {
                con.Open();
                SqlDataAdapter da = new SqlDataAdapter("sp_刀具_load", con);
                da.SelectCommand.CommandType = CommandType.StoredProcedure;
                DataTable dt = new DataTable();
                da.Fill(dt);
                this.Size = new System.Drawing.Size(this.Size.Width, height - (gBAdd新增.Height + 13));
                dGrid刀具管理.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
                dGrid刀具管理.DataSource = dt;
                PublicClass.setRowNumber(dGrid刀具管理);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                con.Close();
            }
        }
        public void ResetText刀具()
        {
            txt刀具編號.ResetText();
            //txt刀具狀態.ResetText();
            txt刀具名稱.ResetText();
            txt品名規格.ResetText();
            txt規格代號.ResetText();
            txt材料編號.ResetText();
            txt建檔數量.ResetText();
            txt保管人代號.ResetText();
            // txt借用人.ResetText();

            txt刀具編號.Text = "";
            //txt刀具狀態.Text = "";
            txt刀具名稱.Text = "";
            txt品名規格.Text = "";
            txt規格代號.Text = "";
            txt材料編號.Text = "";
            txt建檔數量.Text = "";
            txt保管人代號.Text = "";
        }
        private void Enabled_Disibled_新增()
        {
            btn_新增.Enabled = true;
            btn_修改.Enabled = true;
            btn_查詢.Enabled = true;
            //btn_所有.Enabled = true;
            btn_領用.Enabled = true;
            btn_領用.Enabled = true;
            txt刀具編號.Enabled = true;
           // txt刀具狀態.Enabled = true;
            txt刀具名稱.Enabled = true;
            txt品名規格.Enabled = true;
            txt規格代號.Enabled = true;
            txt材料編號.Enabled = true;
            txt建檔數量.Enabled = true;
            txt保管人代號.Enabled = true;
            bt挑選.Enabled = true;
        }
        private void txt刪除_Click(object sender, EventArgs e)
        {
            if (!b刀具Del) txt刪除.Enabled = false;
            
            iflag = 3;
            btn_shixian.Text = "确定";
            this.Size = new System.Drawing.Size(width, height);
            gBAdd新增.Visible = true;
            Enabled_Disibled_delete();
        }
        private void Enabled_Disibled_delete()
        {
            txt刀具編號.Enabled = false;
            txt刀具名稱.Enabled = false;
            txt品名規格.Enabled = false;
            txt規格代號.Enabled = false;
            txt材料編號.Enabled = false;
            txt建檔數量.Enabled = false;
            txt保管人代號.Enabled = false;
            label3.Enabled = false;
            bt挑選.Enabled = false;
        }
        private void dGrid刀具管理_RowEnter(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                int r = e.RowIndex;
                DataGridViewRow row = new DataGridViewRow();
                row = dGrid刀具管理.Rows[e.RowIndex];
                txt刀具編號.Text = row.Cells[0].Value.ToString();
                s1 = row.Cells[0].Value.ToString();
                txt刀具名稱.Text = dGrid刀具管理.Rows[r].Cells[1].Value.ToString();
                txt品名規格.Text = dGrid刀具管理.Rows[r].Cells[2].Value.ToString();
                txt規格代號.Text = dGrid刀具管理.Rows[r].Cells[3].Value.ToString();
                txt材料編號.Text = dGrid刀具管理.Rows[r].Cells[4].Value.ToString();
                txt建檔數量.Text = dGrid刀具管理.Rows[r].Cells[5].Value.ToString();
                tb6 = dGrid刀具管理.Rows[r].Cells[5].Value.ToString();
                txt保管人代號.Text = dGrid刀具管理.Rows[r].Cells[6].Value.ToString();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
        }
       private void btn_新增_Click(object sender, EventArgs e)
        {
            if (!b刀具Insert) btn_新增.Enabled = false;
             
           iflag = 1;
            btn_shixian.Text = "確定";
            ResetText刀具();
            this.Size = new System.Drawing.Size(width, height);
            gBAdd新增.Visible = true;
           Enabled_Disibled_新增();
        }

       private void btn_shixian_Click(object sender, EventArgs e)
       {
           if (iflag == 1)
           {
               if (txt刀具編號.Text == "")
               {
                   MessageBox.Show("請您輸入刀具編號", "錯誤", MessageBoxButtons.OK);
                   txt刀具編號.Focus();
                   return;
               }
               if (txt刀具名稱.Text == "")
               {
                   MessageBox.Show("請您輸入刀具名稱", "錯誤", MessageBoxButtons.OK);
                   txt刀具名稱.Focus();
                   return;
               }
               if (txt品名規格.Text == "")
               {
                   MessageBox.Show("請您輸入品名規格", "錯誤", MessageBoxButtons.OK);
                   txt品名規格.Focus();
                   return;
               }


               if (txt規格代號.Text == "")
               {
                   MessageBox.Show("請您輸入規格代號", "錯誤", MessageBoxButtons.OK);
                   txt規格代號.Focus();
                   return;
               }
               if (txt材料編號.Text == "")
               {
                   MessageBox.Show("請您輸入材料編號", "錯誤", MessageBoxButtons.OK);
                   txt材料編號.Focus();
                   return;
               }

               if (txt建檔數量.Text == "")
               {
                   MessageBox.Show("請您輸入建檔數量", "錯誤", MessageBoxButtons.OK);
                   txt建檔數量.Focus();
                   return;
               }

               if (txt保管人代號.Text == "")
               {
                   MessageBox.Show("請您輸入保管人代號", "錯誤", MessageBoxButtons.OK);
                   txt保管人代號.Focus();
                   return;
               }
               
               else
               {
                   try
                   {
                       SqlConnection con = new SqlConnection(connectionString);
                       con.Open();
                       SqlCommand cmd0 = new SqlCommand("sp_刀具_新增", con);
                       cmd0.CommandType = CommandType.StoredProcedure;
                       cmd0.Parameters.AddWithValue("@刀具編號", txt刀具編號.Text.ToString());
                      // cmd0.Parameters.AddWithValue("@刀具狀態", txt刀具狀態.Text.ToString());
                       cmd0.Parameters.AddWithValue("@刀具名稱", txt刀具名稱.Text.ToString());
                       cmd0.Parameters.AddWithValue("@品名規格", txt品名規格.Text.ToString());
                       cmd0.Parameters.AddWithValue("@規格代號", txt規格代號.Text.ToString());
                       cmd0.Parameters.AddWithValue("@材料編號", txt材料編號.Text.ToString());
                       cmd0.Parameters.AddWithValue("@建檔數量", txt建檔數量.Text.ToString());
                       // cmd0.Parameters.AddWithValue("@年份", DateTime.Parse(txt建檔數量.Text.ToString()).ToString("yyyy-MM-dd HH:MM:ss"));
                       cmd0.Parameters.AddWithValue("@保管人代號", txt保管人代號.Text.ToString());
                       cmd0.ExecuteNonQuery();
                       MessageBox.Show("新增成功");
                       Load_刀具();
                       con.Close();
                      
                   }
                   catch
                   {
                       MessageBox.Show("資料不對");
                   }
               }
           }
           if (iflag == 2)
           {
               if (txt刀具編號.Text.ToString() == null || txt刀具編號.Text.ToString().Equals(""))
                   MessageBox.Show("刀具編號還沒輸入資料");
               else
               {
                   try
                   {
                       SqlConnection con = new SqlConnection(connectionString);
                       con.Open();
                       SqlCommand cmd0 = new SqlCommand("sp_刀具_修改", con);
                       cmd0.CommandType = CommandType.StoredProcedure;
                       cmd0.Parameters.AddWithValue("@刀具編號_1", s1);
                       cmd0.Parameters.AddWithValue("@刀具編號_2", txt刀具編號.Text.ToString());
                      // cmd0.Parameters.AddWithValue("@刀具編號", txt刀具編號.Text.ToString());
                       cmd0.Parameters.AddWithValue("@刀具名稱", txt刀具名稱.Text.ToString());
                       cmd0.Parameters.AddWithValue("@品名規格", txt品名規格.Text.ToString());
                       cmd0.Parameters.AddWithValue("@規格代號", txt規格代號.Text.ToString());
                       cmd0.Parameters.AddWithValue("@材料編號", txt材料編號.Text.ToString());
                       cmd0.Parameters.AddWithValue("@建檔數量", txt建檔數量.Text.ToString());
                       cmd0.Parameters.AddWithValue("@保管人代號", txt保管人代號.Text.ToString());
                       cmd0.ExecuteNonQuery();
                       MessageBox.Show("修改成功");
                       Load_刀具();
                       con.Close();
                   }
                   catch
                   {
                       MessageBox.Show("資料不對、修改不成功");
                   }
               }
           }
           if (iflag == 3)
           {
               if (txt刀具編號.Text.ToString() == null || txt刀具編號.Text.ToString().Equals(""))
                   MessageBox.Show("刀具編號還沒輸入資料");
               else
               {
                   try
                   {
                       DialogResult answer = MessageBox.Show("您確定要出入這個產品碼", "警報", MessageBoxButtons.YesNo);
                       if (answer == DialogResult.Yes)
                       {
                           SqlConnection con = new SqlConnection(connectionString);
                           con.Open();
                           //string sqldel = "select 刀具編號 from 刀具 inner join 刀具領用1 on 刀具.刀具編號 = 刀具領用1.刀具編號";
                           ////SqlCommand delall = new SqlCommand(sqldel, con);
                           //if (sqldel)
                           //{
                           //}
                           
                           SqlCommand cmd0 = new SqlCommand("sp_刀具_刪除", con);
                           cmd0.CommandType = CommandType.StoredProcedure;
                           cmd0.Parameters.AddWithValue("@刀具編號", txt刀具編號.Text.ToString());
                           cmd0.ExecuteNonQuery();
                           MessageBox.Show("刪除成功");
                           Load_刀具();
                          // hiden();
                           con.Close();
                       }
                       else
                       {
                           Load_刀具();
                           return;
                       }
                   }
                   catch
                   {
                       MessageBox.Show("資料不對、可以資料在使用、刪除不成功");
                   }
               }
           }
       }

       private void bt挑選_Click(object sender, EventArgs e)
       {
           Cuttingtool_manager_seach1 frm = new Cuttingtool_manager_seach1(txt保管人代號);
           frm.ShowDialog();
       }

       private void txt保管人代號_TextChanged(object sender, EventArgs e)
       {
           SqlConnection con = new SqlConnection(connectionString);
           try
           {
               con.Open();
               String temp = "";
               string strcmd = String.Format("select * from 刀具保管人 where 保管人代號=N'{0}'", txt保管人代號.Text);
               SqlCommand cmd = new SqlCommand(strcmd, con);
               var x = cmd.ExecuteReader();
               //int icount=0;
               while (x.Read()) temp = x[1].ToString();
               if (temp == "") label3.Text = "";
               else label3.Text = temp;
           }
           catch (Exception ex) {
               MessageBox.Show(ex.ToString());
               return;
           }
       }
        
       public void hiden()
       {
           gBAdd新增.Visible = false;
           this.Size = new Size(width, height - gBAdd新增.Height);
           btn_新增.Enabled = true;
           btn_修改.Enabled = true;
           txt刪除.Enabled = true;
       }
       private void btn_修改_Click(object sender, EventArgs e)
       {
           if (!b刀具Edit) btn_修改.Enabled = false;
           
           iflag = 2;
           btn_shixian.Text = "更新";
           this.Size = new System.Drawing.Size(width, height);
           gBAdd新增.Visible = true;
           Enabled_Disibled_新增();
       }

       private void btHide_Click(object sender, EventArgs e)
       {
           gBAdd新增.Visible = false;
           this.Size = new Size(width, height - gBAdd新增.Height);
           btn_新增.Enabled = true;
           btn_修改.Enabled = true;
           txt刪除.Enabled = true;
       }

        private void btn_領用_Click(object sender, EventArgs e)
       {
           flag = "2";
           try
           {
               int r = dGrid刀具管理.CurrentCell.RowIndex;
               string id1 = dGrid刀具管理.Rows[r].Cells[0].Value.ToString();
               string id2 = dGrid刀具管理.Rows[r].Cells[1].Value.ToString();
               string id3 = dGrid刀具管理.Rows[r].Cells[2].Value.ToString();
               string id4 = dGrid刀具管理.Rows[r].Cells[3].Value.ToString();
               string id5 = dGrid刀具管理.Rows[r].Cells[4].Value.ToString();
               string num = dGrid刀具管理.Rows[r].Cells[5].Value.ToString();
               string id7 = dGrid刀具管理.Rows[r].Cells[6].Value.ToString();
               tb1 = id1; //cb
               tb2 = id2;
               tb3 = id3;
               tb4 = id4;
               tb5 = id5;
               tb6 = num;
               tb7 = id7;
               frmCutting_lingyong frm = new frmCutting_lingyong(flag, tb1, tb2, tb3, tb4, tb5, num, tb7);
               frm.ShowDialog();
               Load_刀具();
           }
           catch (Exception ex)
           {
               MessageBox.Show(ex.Message);
           }
       }

        private void btn_查詢_Click(object sender, EventArgs e)
        {
            if (!b刀具Search) btn_查詢.Enabled = false;
            
            try
            {
                SqlConnection con = new SqlConnection(connectionString);
                con.Open();
                string sp = "sp_刀具_查詢12";
                SqlCommand cmd0 = new SqlCommand(sp, con);
                cmd0.CommandType = CommandType.StoredProcedure;
                if (txt刀具編號_seach.Text != "") cmd0.Parameters.AddWithValue("@刀具編號", txt刀具編號_seach.Text.ToString());
                if (txt品名規格_seach.Text != "") cmd0.Parameters.AddWithValue("@品名規格", txt品名規格_seach.Text.ToString());
                if (txt規格代號_seach.Text != "") cmd0.Parameters.AddWithValue("@規格代號", txt規格代號_seach.Text.ToString());
                if (txt材料編號_seach.Text != "") cmd0.Parameters.AddWithValue("@材料編號", txt材料編號_seach.Text.ToString());
                if (txt建檔數量_seach.Text != "") cmd0.Parameters.AddWithValue("@建檔數量", Int32.Parse(txt建檔數量_seach.Text.ToString()));
                if (txt保管人代號_seach.Text != "") cmd0.Parameters.AddWithValue("@保管人代號", txt保管人代號_seach.Text.ToString());
                //if (textBox1.Text != "") cmd0.Parameters.AddWithValue("@刀具編號", textBox1.Text.ToString());
                //cmd0.Parameters.AddWithValue("@領用日期From", txt領用日期From_seach.Value);
                //cmd0.Parameters.AddWithValue("@領用日期To", txt領用日期To_seach.Value);

                if (txt領用數量_seach.Text != "") cmd0.Parameters.AddWithValue("@領用數量", Int32.Parse(txt領用數量_seach.Text.ToString()));
                //cmd0.Parameters.AddWithValue("@歸還日期From", txt歸還日期From_seach.Value);
                //cmd0.Parameters.AddWithValue("@歸還日期To", txt歸還日期To_seach.Value);
                if (txt歸還數量_seach.Text != "") cmd0.Parameters.AddWithValue("@歸還數量", Int32.Parse(txt歸還數量_seach.Text.ToString()));
                SqlDataReader sqlreader = cmd0.ExecuteReader();
                //cmd0.ExecuteNonQuery();@車輛成本中心@部門代號@人員名稱 @電話
                DataTable dt = new DataTable();
                dt.Columns.Add("刀具編號");
                dt.Columns.Add("品名規格");
                dt.Columns.Add("規格代號");
                dt.Columns.Add("材料編號");
                dt.Columns.Add("建檔數量");
                dt.Columns.Add("保管人代號");
                dt.Columns.Add("領用日期");
                dt.Columns.Add("領用數量");
                dt.Columns.Add("歸還日期");
                dt.Columns.Add("歸還數量");
                //int k=1;
                while (sqlreader.Read())
                {
                    DataRow dtrows = dt.NewRow();
                    dtrows["刀具編號"] = sqlreader["刀具編號"];
                    dtrows["品名規格"] = sqlreader["品名規格"];
                    dtrows["規格代號"] = sqlreader["規格代號"];
                    dtrows["材料編號"] = sqlreader["材料編號"];
                    dtrows["建檔數量"] = sqlreader["建檔數量"];
                    dtrows["保管人代號"] = sqlreader["保管人代號"];
                    dtrows["領用日期"] = sqlreader["領用日期"];
                    dtrows["領用數量"] = sqlreader["領用數量"];
                    dtrows["歸還日期"] = sqlreader["歸還日期"];
                    dtrows["歸還數量"] = sqlreader["歸還數量"];
                    dt.Rows.Add(dtrows);
                }

                dGrid刀具管理.DataSource = dt;
                PublicClass.setRowNumber(dGrid刀具管理);
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                //con.Close();
            }
        }

        private void btn_取消_seach_Click(object sender, EventArgs e)
        {
            if (!b刀具Search) btn_取消_seach.Enabled = false;
           // cb_年份.Checked = false;
            txt刀具編號_seach.Text = "";
            txt品名規格_seach.Text = "";
            txt規格代號_seach.Text = "";
            txt材料編號_seach.Text = "";
            txt建檔數量_seach.Text ="";
            //cb_車輛_預保日.Checked = false;
            txt保管人代號_seach.Text = "";
            //txt領用日期From_seach.Text = "";
            //txt領用數量_seach.Text = "";
            //txt歸還日期From_seach.Text = "";
            txt歸還數量_seach.Text = "";
            Load_刀具();
        }

        private void btnlikai_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void txt建檔數量_seach_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) || e.KeyChar == '.')
            {
                e.Handled = true;
                MessageBox.Show("很抱歉，請您輸入號碼", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void txt建檔數量_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar) || e.KeyChar == '.')
            {
                e.Handled = true;
                MessageBox.Show("很抱歉，請您輸入號碼", "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void bt_匯出_Click(object sender, EventArgs e)
        {
            Export_Excel excel = new Export_Excel();
            DataTable dt = (DataTable)dGrid刀具管理.DataSource;
            excel.Export(dt, "Sheet1", "刀具資訊");
        }

        private void btn_guihuan_Click(object sender, EventArgs e)
        {
            frm_cuttinglingyongjilu frm = new frm_cuttinglingyongjilu();
            frm.ShowDialog();
        }


    }
}
